Now that we have the server service setup, let's go ahead and start scripting the functionality for
our starting menu GUI.
So instead of starter GUI, we have our starting menu here.
And let me go ahead and enable UI visibility so we can see it more clearly.
And we have a bunch of different frames in here that we're going to have to script.
So this is going to be our main frame right here.
We're going to have two buttons one to go to the server frame and one to go to the about menu.
So if I enable the visibility for our about menu it'll just show some text like what this game is about
and what we're supposed to do.
And it'll have a back button inside of it.
And then for our server menu we'll go down to this one right here.
We'll enable the visibility of this one.
And let me disable the visibility of the main one.
So we'll disable that.
So this will be our server menu.
We'll have the list of servers that currently exist in the game.
And then when we click on a server the plan is to have this button here become bright again.
So it's not darkened.
And then we can join that server.
Or we can create a server or go back to the main menu.
So I have two other text buttons here, ones for example player and one is example server.
We're going to use these to create a server.
And then we're going to use these to create ones for players.
So they're going to like represent a list of players in the game.
So I'll give you an example.
If I copy this and go to my server menu, there's a list in here.
And if I paste that in there it'll let me enable the visibility.
It'll display the name of the server and how many people are in that server.
And of course, since this is a list with a UI list layout, we can duplicate this as many times and
the scrolling frame will update automatically to fill in.
You know, however, many people are, uh, having their servers in here.
And then let's say they hit the Create server button.
Then we'll disable the visibility of this menu.
And then we'll open up the Create server menu.
Here.
It'll ask them what the server size will be.
So we'll need to script this plus and minus button.
We'll also have functionality for whether or not they have a password.
So if they hit this button here it'll display um a little text box.
So if we go to the settings frame here there is a password input.
So it'll enable the visibility of that.
It'll say input password.
And we can type in our password there.
And then we'll create the server.
Let me go ahead and disable the visibility here.
So once we create a server then it'll open up our in server menu owner frame.
So we're the owner of the server.
It'll display that this is your server.
It'll have a list of all the other players that are in the game.
And we'll be able to select one of those players and remove them if we'd like.
We can delete the server or we can go ahead and start the game.
So let me copy one of these example players, and I could go ahead and put it inside of the player list
and let me enable the visibility on that.
So it'll have the name of the player and then a little image of them.
And again we can put as many as these in here depending on the size of the server.
And then let's say, um, they hit start game.
That means that, um, our teleport menu is going to fade in and.
Oh, looks like the transparency is set to be completely transparent, but it'll have a black screen
fade in and it'll just have some text there that says teleporting.
And then some other frames in here.
Of course we have one for the message.
So like if any player needs a message displayed on their screen, it'll say notice the message goes
here.
And then they can hit okay to close out this menu.
And of course, we have another menu here to display when you're in a server as not the owner.
So to display the name of the person who owns the server, it'll show all the other players in the server.
And your only option is to leave the server if you'd like.
Another frame we'll have in here is for entering a password.
So let's say a player requests to join a server.
But that server has a password.
Then it'll enable this enter password screen.
We'll type in the password.
We'll hit submit.
If the password is correct then it will open up that in server menu and place us in the server.
Otherwise it'll display the message saying like incorrect password.
And then we can try again.
Or we can go ahead and hit back to go back to the server menu.
So a pretty simple guy, just a lot of different frames that we're going to have to script.
And there's also a sound in here for when we click buttons.
It'll just play this click sound.
So let's go ahead and go inside of starter player and inside of starter player scripts.
The script for our GUI isn't actually going to be inside of the GUI, though.
That is one way you could do it.
But I do want to keep all of my scripts within the same folder.
So we'll have our starting menu handler right here.
And the three services we're going to need in here, of course, is going to be replicated storage.
We're going to need the player service.
And then we're going to need the tween service.
Now we're going to need a lot of variables in here, because we're going to be referencing all different
sorts of buttons and frames in here.
But we need to first create the table that is going to store all of the functions, or basically just
be the table that gets returned from this module script.
So we'll just call it main guy.
And we'll return main guy at the end of our module script.
And of course we're going to have a function in our main guy.
For initializing everything, or basically connecting all of the different functions to the different
button events.
But besides that, let's go ahead and start filling out our variables.
So first I want to make a reference to the, uh, server event or that remote function that's inside
of replicated storage.
So replicated storage, dot events, dot remotes, dot server event.
We do not have to use wait for child because this script will only run once the game is loaded.
And since our.
Remotes here are already existing within studio.
That means they're going to be part of the snapshot the player will download when they join the game,
so there's no need to use wait for child.
We can reference our update guy event as well.
And then of course we're going to reference our server actions.
Enum.
Server actions.
Enum.
We're going to require the module script that is in the modules enums folder.
Or let me rename this to Server Action enums.
Next I'm going to create a reference to the local player, so I'll just call it local player.
It's equal to players dot local player.
I'm going to make a reference to the guy itself as well.
And since I have disabled reset on spawn, we do not have to update this variable every time.
Let's say the player resets and the player shouldn't be able to reset because we've disabled it.
But let's say an exploiter somehow resets themselves or something weird happens.
We'll still be able to reference the same guy because I've disabled the reset on spawn property.
So what we need to do is we need to reference our local player, get their player guy folder, and this
is where we need to use wait for child.
We need to wait for our starting menu because it's not going to exist right away.
It has to get duplicated or cloned from the start of guy into our player object.
So we have to make sure to wait for the starting menu.
However, once we finally waited for the starting menu, we don't need to wait for any of the other
descendants of the starter menu, so that means we can create a reference to our click sound using Guy,
click sound or click.
And then we can go ahead and start making some references to different frames.
So the first frames I'm going to make references to or the buttons I'm going to make references to is
the server frame which is guy example server and then the player frame.
Example player.
Now this section here is going to be for the main menu.
So we'll have a reference to the main frame.
So we'll just call it main is equal to guy dot main.
And we'll have the main server menu button.
So that's equal to main dot server menu button.
So that's the button we'll click to go into the server menu.
And then we'll also have the about button.
So we'll call it main about button.
So main about button.
And if you're noticing or not I'm starting all of these names out with the frames name.
That way when we type out the name of it, the auto fill will allow us to display all of the different
buttons or frames that belong to a particular frame.
So now I can make a section for our about menu.
So about menu is equal to G dot about menu.
And then the back button we'll just call about back button.
About menu dot go back button.
We'll have a section for the server menu.
So this will be server menu GUI server menu.
We'll have a reference to the Create Server button.
So we'll call it create button equals server menu dot create server button.
We'll have one for joining a server.
And then we'll have one for going back to the main menu.
So back button equal to server menu dot.
Go back button.
The next frame we're going to create some references to is when you're inside of the server.
So we'll call it in server menu.
So in server menu.
Is equal to guy in server menu.
And then we only have a leave button for that.
So we'll just call it in server leave button which is in server menu dot leave server button.
Will next have a reference to all of the different buttons in the owner menu.
So in Server owner menu we'll call it in owner menu GUI dot in server menu owner.
So we'll have a delete button reference.
So in owner uh delete.
Button is equal to in owner menu.
Dot delete server button.
Uh, we'll have one for the remove player button.
And then we'll have one for starting the server.
So in owner start button is equal to in owner menu dot start game button.
Uh the next one will have to make references for is the menu to create a server.
So we'll call it Create server menu.
So create menu is equal to G dot create server menu.
Um we'll have a reference to the settings frame that is in that menu.
So settings frame is equal to create menu dot settings frame.
We have that other menu for when we enter in a password or not, so we'll call it password.
Toggle menu settings frame dot password toggle.
And then we also need to create a reference to all those other different buttons.
So like the create password toggle button which is equal to password toggle menu dot I believe it's
called toggle.
Yep.
There it is.
We have that password input box so we can call it password input.
We can call it box or menu.
I'll just call it menu.
Equal to settings frame dot password input.
We have that frame for representing the server size.
I'll just call it server size menu, just to say consistent with the menu name format.
So that's equal to the settings frame dot server size.
And then we'll create a reference to those two buttons for increasing and decreasing the server size.
We'll call it create increase button equal to server size menu dot plus and then create decrease button
which is equal to server size menu minus.
And then we'll also have a reference to that create button.
So create button is equal to create menu dot create server button.
And then we'll have a reference to that cancel button.
So create cancel button is equal to create menu dot cancel server button.
The next frame we need to make references for is the entering a password frame.
So we'll call it Enter password menu.
So enter password menu is equal to g dot enter password.
We will have that input box.
So enter password.
We'll just call it input is equal to enter password menu dot text box.
Um, we'll have a reference to the submit button, so enter password.
Submit button is equal to enter password menu dot submit button and then enter password go back button.
We'll just call it back button is equal to enter password menu dot go back or it's the back button.
Okay.
Stay in there.
We're almost done.
We'll need to have a reference to the message menu.
So message menu is equal to G dot message menu.
And then we just have that one okay button in there.
So we'll just call it message menu okay.
Button is equal to message menu dot okay button.
And then the last frame or the last menu will have is that teleport menu.
So teleport menu is equal to GUI dot teleport menu.
All right.
We're good to go there with all the references to the different frames and buttons.
Now let's go ahead and create some other variables.
Uh, we'll have a variable to keep track of the selected server, because what's going to happen is
we'll have that server list on our screen.
So let me go ahead and enable the server menu.
So we'll have all the listed servers in here.
And we'll be able to click a server.
It'll highlight that server and it'll make this uh join server button usable.
So we're going to have this variable keep track of what our selected server is.
So we'll just call it selected server.
And right now we're just going to set it to nil.
We're also going to do the same thing for when the owner of a server selects a player.
So we'll call this um selected player.
And we're also going to set it to nil.
Um we're going to use a boolean to keep track of whether or not we have enabled the password for a server.
So let's say we're creating a server and we want to have a password.
We'll use a boolean to keep track of whether or not we want a password.
So we could just call this variable like is password enabled or is password like on.
We'll set it to false as default.
And then, uh, another variable we're going to have is to keep track of whether or not we currently
own a server.
And this is just a little bit of some server side protection.
That way we can prevent us from firing some events that we aren't supposed to because we're owning a
server.
This isn't going to stop exploiters, but it will stop regular players in your game from doing things
that you don't expect them to do because they're an owner of a server.
So we'll just call it currently owning server, and we're going to set that to false as well.
Now we're going to set some constants here.
These constants are going to represent the, um, button colors.
So this, uh, button here has a faded out color.
So we'll need to keep track of that color.
And we're also going to need to keep track of this brighten color.
And then we're going to have two other constants to represent the minimum and maximum server size.
So what we could do here is we could create a constant.
We'll just call it max server size.
We'll set it to ten and one for a minimum server size.
And we'll set it to one.
The button color will be the one for the default bright color.
So from RGB and we can just basically just go in here and find one of these buttons like go back, copy
this background color and paste that in there.
And then we'll create another one.
We'll just call it button color dark.
So color three from RGB and we'll go to the Join server button.
Here's the darkened color.
We'll copy that and paste that in there.
And actually, I don't remember whether or not we have verified the size of a server on the server side.
So actually let me let's let's go ahead and check in here.
So when we go to create a new server object, the max size here are we should verify that the number
that gets passed to this constructor is greater than one and less than ten, because the client is going
to be passing this information to the server.
We don't want exploiters creating servers with like a negative size or a size that's like a 1000.
So what I could do is I'm going to add one more if statement in here, and I'm going to check if max
size.
If it's less than one, or if max size is greater than ten, then we're going to return false and say
something like size of server is restricted to 1 to 10 players.
So back to our local script.
Let's go ahead and fill out our private functions section.
Now since we have a lot of buttons in our guy, I'm actually going to create a function dedicated to
just playing the click sound.
That way in the future, if we ever wanted to change the click sound, or maybe add some extra functionality
or features to like the click sound, then we can do it directly from a single function.
So I'm just going to create a function called um play Click sound.
And all it's going to do at the moment is just play our click sound.
But in case we ever wanted to add more features in the future, we can do so right in this function.
And we don't have to go and rewrite all of our code.
So I'll just leave a note here for any future functionality.
Next up, I'm going to create a function for when we click any of the server frames.
So these example server text buttons we want to listen for when we click one of those.
And when we do we can create a highlight around them.
So I'll call this function on server frame clicked.
And then we'll do the same thing for when a player frame is clicked.
So on player frame clicked.
We'll have some functionality in there as well.
We'll have a function for displaying a message on the screen using the display menu, so we'll call
it Display Message.
We'll have a function for creating a server frame.
So when the server tells us to create a new server frame because someone just created a server, we'll
use this function to do it.
And we'll also do the same for creating a player frame and destroying a server frame and destroying
a player frame.
So here I'll just create a function for destroying a server frame.
We'll have a function for creating a player frame.
And then we'll have a function for destroying a player frame.
Next up, I want to have a function for completely clearing out the player list that's inside of our
in server menu.
Because let's say I leave a server, then I want to delete everything that's inside of our player list.
That is not the default, uh, different UI properties here.
So I want to delete any example players that were inside of our player list.
So I'll just call this function something like Clear Player list.
And that's it.
I'll have a function for joining a server.
Um, and then one last function we'll need is for updating the server count for a particular server.
So we'll just call this update server count.
And I think that's all of the private functions that we're going to need for our starting menu.
Now inside of our initialize function here we are going to have to do a bunch of stuff because this
is the function where we're going to connect, uh, different functions to all of the different buttons.
We're going to be listening to that update UI event and all that kind of good stuff.
So I guess the first thing we could do is we could listen to our update guy event.
So on client event we're going to connect a Lambda function.
And remember we get passed an action and some arguments supplied to that action from the server.
So one of those actions could be inside of our server action enums dot two client.
And one of the actions we could first do is adding a server.
So let's say the server tells us to add a new server.
Then what we could do is we could get that server to add.
And if you remember, it's the first, uh, element within our args table.
So that's our server we want to add.
And we could literally just call our create server frame function and pass this server object to this
function.
And actually, let's go ahead and fill out this function since we're calling it right here.
So up in our create server frame we're getting past the server we want to create.
So we'll just call it server to add.
And remember in our server service when we tell the player to add a server we're passing to them right
here.
Uh, a server object that was created by our server service constructor.
So that means that this object is going to store all of the, um, let me find it.
It's going to tell us the owner, it's going to tell us whether or not it has a password the size,
who's in the server, blah, blah, blah, blah, stuff like that.
So what we could do.
Is we're going to loop through every single server that currently exists within our server menu dot
list, and we're going to get all of the children.
And we're going to make sure that the server the server is telling us to create doesn't already exist.
For some reason, if it does already exist, then we don't want to do anything right.
We don't want to have duplicate servers in our server menu list.
Now.
One way we could keep track of the different owners for these server frames is by setting an attribute
on them that represents the name of the owner.
So before we do that here, when we create a new server, what I'm going to do is I'm going to make
a clone of our server frame.
And we're going to set an attribute on this clone and we'll call it owner.
So this is the owner of the server.
And it's going to be equal to the server to add dot owner.
And we're going to get the name of the owner.
So that way we can keep track of every single one of those different uh example server buttons.
We're going to set an attribute on them, the owner of the server.
That way when we select one of these buttons and we want to join a server, we just get that name attribute
and pass that name to the server.
And then we're also going to set an attribute of whether or not the server has a password.
So we can call it has password.
And we'll set that equal to server to add has password.
So that'll be true or false.
Then what we could do is that inside of this clone.
We can set the server name, which is a text label, and set the text equal to server to add.
Get the owner get their name.
And then we can literally just concatenate it with an apostrophe s and say server.
So whatever the name of the owner is, we'll put an apostrophe s and tell them that this is their server.
Next we need to set the player count for the server.
So clone dot player count dot text is going to be equal to.
We're going to get the number of players in the server.
So basically number and server to add dot players in server.
We'll concatenate it with a slash and then concatenate it with the server to add dot max size.
So if there's three players in the server and the max size is ten, it'll display three slash ten.
Then once we set the text for this clone, we can set the parent.
Equal to the server menu list.
We'll make sure that this is now visible on the client.
And then what we could do here is we could get this clone, and then we can listen for when we click
it.
So mouse button one click we're going to connect a lambda function.
And we're going to call that on server frame clicked function.
And to keep track of which server frame we clicked we're going to pass the clone itself to this function.
So now let's go ahead and actually fill out this function as well.
So on our on server frame clicked function, we get past this particular, uh, text button.
So we'll just call it, uh, either text button or for simplicity's sake, we'll just call it frame.
And when we click it, of course we want to play our click sound.
So play click sound.
Then we want to check if we have a server already selected.
So if we already have a server selected, then what we want to do is we want to get that selected server,
which will be a reference to whatever button or text button it is.
And we want to set the border or the UI stroke within that server.
We want to set the visibility to nothing or basically just disable the UI stroke.
So border dot enabled is equal to false.
Then with this newly selected, um, text button, what we're going to do is we're going to do frame
dot border dot enabled is equal to true.
And then we're going to update our selected server variable equal to this new frame.
And now, because we've selected a new server, that means inside of our GUI, if we go to our server
menu.
So let's say there's a server list in here.
We click a server right.
We've selected a server.
Then we want to make this button usable.
So we want to change the background color of our join server button.
So we can do server, uh, join button reference or server join button and set the background color
equal to the default button color.
And that's all we need to do for this function.
Okay.
Looks good.
Let's go ahead and listen to a different action now.
So let's say the action that the server wants us to do is equal to like let's say removing a server.
So server action enums dot two client.
Let's say the server tells us to remove a server.
Then what we could do is we could get the server that the, you know, server wants us to remove.
And that's going to be the first argument in that args table.
And what we could do is we could call our destroy server frame function and pass the server that we
wish to remove.
So inside of our destroy server frame function, what we could do is we could loop through every single
server that exists in our server menu list.
So in Ipairs server menu dot list and we're going to get all of the children.
And what we're going to do is we're going to find the server whose owner attribute matches the name
of the server we want to destroy.
So we'll get past the server that we need to remove.
And we're going to check if this, uh, current server.
Or oops, let me type it out for fully current server.
Get attribute owner.
If the owner is equal to server two, remove dot owner dot name.
Then what we need to do is we also need to check whether or not we have this server selected.
So let's say inside of our server menu we've selected a server.
And then all of a sudden that server gets deleted.
Right.
So we need to clear out our selected server variable.
So if selected server.
So if we have a server selected and the selected servers attribute get attribute.
Owner is also equal to the owner of the server we need to remove.
Then what we're going to do is we're going to get the border within our selected server set, enable
to false, and then we'll set selected server to nil.
And then what we're going to do is we're going to set the server join button dot background color equal
to the dark button color or button color dark.
Because we don't have a server selected anymore.
And then we can just destroy this server frame.
And that's all we need to do there.
Now let's say the next action the server wants us to do.
Is to add a player to a player list.
So if action is equal to server action enums dot two client dot add to player list.
Then we can get the player they want us to add, which is again the first index in our arguments table,
and we can call our create player frame function and pass the player we wish to add.
So now let's go ahead and fill out this function as well.
So back up at our Create player frame function.
We're going to get the player that the server wants us to add.
And just like what we did in our create server frame function, we're going to loop through all of the
current players and make sure that this player doesn't already exist.
So we actually need to finish filling out this for loop.
I forgot we didn't finish filling that out yet, but basically in here, what we need to do is we need
to check if this current server get attribute owner.
Is equal to server to add owner dot name.
And if it is, we're just going to return out of this function because we don't need to create a new
server frame.
And then we're basically actually just going to do the exact same thing for creating a player frame.
We're going to loop through every single, uh, current player.
Inside of our in server menu dot player list, and we actually have two different player lists, one
inside of our in server menu and one inside of our in server menu owner.
So you know what I'm going to save this for loop for later, because we need to make an if statement
to check whether or not we're currently owning a server, which will determine whether or not we are
in the in server menu, or if we are in the in server menu owner.
So instead, what I'm going to do is I'm going to create a clone of our player frame.
And we're going to set an attribute on this clone of owner, which will be the player to add dot name.
So this is the owner of this particular example player text button.
And then we're going to set the clone dot player name text label dot text equal to the player's name.
So player two add dot name.
And then what I'm going to do here is I'm going to try to get the thumbnail of this user by using a
function within the player service called get user thumbnail async.
And since it's an asynchronous function, we need to use p call on it.
So I'm going to create two variables one called success, one called result equal to p call.
And we're going to call inside of players the get user thumbnail async function.
This is a function that uses a colon.
So we need to pass the player service itself as the first argument.
Then we need to pass the ID of the player that we want to get the thumbnail for.
So we could do player to add dot user ID.
And if we were successful in getting this image, then we can set the clone dot portrait, which is
an image label, and set the image property equal to the result from our P call.
Now we can use our currently owning server variable to check if we are currently owning a server.
So if currently owning server then we need to loop through our in server or in owner menu.
Otherwise we need to loop through our um in server menu when we aren't an owner.
So what we're going to do here is we're going to loop through every single frame in Ipairs in the owner
menu.
So in owner menu and get the player list.
And we're going to get all the children in there.
And what we're going to do is we're going to check if this frame get attribute owner.
Is equal to this player we want to add.
So if player to add dot name is equal to the attribute on this frame, then for some reason we already
have a frame for this player.
We don't need to create a new one.
So we're just going to destroy this clone we created.
So clone destroy.
And then we're just going to return out of this function.
Otherwise we can set clone dot mouse button one click connect a function to it.
And we're going to call the on player frame clicked.
And again we're going to pass this frame itself.
And then we can set the parent of this frame to be in the owner.
Menu dot player list.
Otherwise, if we aren't currently owning a server, that means we are an individual in somebody else's
server and we need to update the player list in a different frame.
So we're basically just going to do the exact same for loop here, but instead we need to loop through
every single frame that is inside of the Inn server menu.
And we need to see if that frame has an attribute that's equal to this player we want to add.
If they already exist, then we don't need to create a new clone.
And we also don't need to listen to clicking on a player frame, because when we are inside of our in
server menu.
So let me enable this and close out this one.
When we're in here, we don't have the ability to kick other players.
All we need to do is just sit in here and just see the other players that are going to be with us.
So the only thing we need to do here is set the parent for this clone to be in server menu dot player
list.
And then once we've done all of that, we can just set the visibility of this clone equal to true.
And actually I made one small mistake up here with the get user thumbnail async function.
We need to pass another thing to this function which is an enum.
So enum dot thumbnail.
I believe it's type.
We want to get a headshot of this player or a capture of their head.
And then we also need to pass the enum dot thumbnail size.
And we're just going to get a size of 180 by 180.
It doesn't really matter.
And then we can get the result from this p call and set the image on the portrait.
Okay.
Seems good.
Now let's go ahead and fill out our on player frame clicked function.
Because why not.
So what do we want to do when a player frame gets clicked?
Well, we want to play the click sound of course.
And then we want to check if we have a selected player already.
So if the owner of the server already has a selected player, then we're going to do selected player.
Get the border that's in there as well, and set the enabled property to false.
And then since this function also gets passed a frame, we want to set the border dot enabled on this
frame to true.
Selected player is going to be equal to this new frame.
And then we need to update the color of the remove player button that's in the owner menu.
So when we are the owner of a server so in server menu owner and we select a player, we want to change
the background color of our remove player button.
So in owner remove player button dot background color is equal to button color.
All right.
So far we are looking good.
Let's go ahead and listen to a different action on the client.
So let's say the server wants us to remove a player from a player list.
So if the action is equal to server action enums dot two client dot remove from player list.
Then when we need to do is we need to get this player we need to remove.
And then we need to destroy the player frame for this particular player and pass player to remove.
So let's go ahead and fill out this function.
So to destroy a player frame.
We need to decide which frame we need to destroy it out of, because again, we're going to have two
different player lists, one in the server menu and one in the server menu if you're the owner of a
server.
So if we are currently owning a server, then we need to loop through every single frame that is in
Ipairs in owner menu dot player list.
And what we need to do is we need to check if the frame get attribute owner is equal to player two.
Remove dot name.
Then we can go ahead and destroy this frame.
However, we also need to check if we have a selected player, right?
If the owner of the server has a selected player, we need to make sure it's not the one that we're
getting rid of.
And if it is, we need to update our selected player variable.
So if we have a selected player and selected player get attribute.
Owner.
Is equal to player to remove name.
Then we can just do selected player.
Dot border dot enabled equal to false.
Selected player.
Can be set to nil.
And then in owner remove player button, we need to update that background color back to be dark.
Now another way we could do this as well.
Instead of having this long if statement here I just realized is we could instead.
Um, see if this frame we're looping at is equal to the same frame that's stored within selected player.
So instead what we could do is we could see if frame is equal to selected player.
And if it is, then we can do this garbage right here.
And we can actually do the exact same thing for when destroying a server frame.
So if the.
Current server is equal to the server or selected server.
Oops.
We're doing the long line here.
So if.
The current server is equal to the selected server, then we can go ahead and update our selected server
variable.
Okay, much more concise there.
So now we need to add our else statement here for when we are in the other player list or the other
menu.
So for every single frame.
And I pairs in server menu dot player list get children.
What we're going to do is check if this frame get attribute owner.
Is equal to player two.
Remove dot name.
Then we'll just destroy this frame.
And that's it for our destroy player frame function.
Let's listen to some more actions.
So let's say the action.
Is equal to server action enums dot two client dot.
Let's say we were removed from a server, right?
If we were removed from the server, then what we want to do is we want to set the in server menu dot
visibility equal to false.
We want to set the visibility of our server menu to true.
And we want to display a message.
So when we get this action given to us, we're going to be also given a message.
So inside of server service, when we are removed from server we are given a message like you have been
kicked from the server or you have left the server.
So we want to go ahead and display that message on our screen.
And we can actually go ahead and fill out that function as well, because why not?
This should be fairly easy.
All we're going to do is get a message.
In our message menu, we're going to set the message text label dot text equal to this message.
And we're going to set the visibility of our message menu to true.
And that's all we need to do there.
Now, another action we're going to have to listen to is, let's say the server wants us to update the
server count for a particular server.
So two clients update server count.
Then we're going to get the server to update.
And we're going to call our update server count function and pass the server.
We need to update the server count on.
So let's go ahead and fill out this function as well.
We'll scroll up here.
And when we need to do is we need to loop through every single server.
And I pairs server menu dot list get children.
And what we're going to do is we need to check if this current server get attribute owner.
Is equal to the server that is passed to this function.
So server to update.
Server to update dot.
Owner dot name.
And we're going to set the current server, get that player count text label, set the text equal to
the number of players in server to update dot players in server, concatenate it with a slash and then
concatenate it with server to update dot max size.
And that's all we need to do there as well.
Now, let's say the next action we need to do.
Is we need to enable the teleport on our screen or that teleport menu, which I believe is our last
action.
So if the action is equal to server action enums dot two client dot teleport.
Then we're going to set the visibility of our teleport menu to true.
We're going to use our tween service to create a new tween on our teleport menu dot text label.
We can do a tween info of something just like 0.5 seconds.
And we want to set the text transparency to zero.
So that way it's fully opaque.
And then we can just play this tween.
And we're going to create a tween.
On the teleport menu itself as well.
Again, we'll do a tween info of 0.5 seconds.
And we're going to set the background transparency to be fully opaque.
And we're going to play this tween as well.
Now we're going to do here is we're just going to have a while loop that's just going to update the
text that is inside of the teleport menu.
So we're just going to do something like teleporting and then dot dot dot reset it back and do dot dot
dot and so on.
So while true what we're going to do is we're going to do teleport menu dot text label dot text is equal
to teleport menu dot text label dot text and concatenate it with a period.
Because inside of our teleport menu, our text label already just says teleporting.
We're going to wait for 0.5 seconds and if the teleport menu dot text label dot text.
Is equal to.
We'll just do teleporting dot dot dot.
Then we need to set the teleport menu dot text label dot text back to teleporting.
And then we'll also wait for like 0.5 seconds.
Now, just in case, for some reason, our teleport fails.
Um, we should kick the player out of the server and tell them that they failed to teleport.
Otherwise they're going to have this teleport menu stuck on their screen forever.
So what I'm going to do is I'm going to create a variable.
I'll just call it last tick.
It's equal to tick.
And we're going to do is we're going to check if the current tick subtracted by this last tick is let's
say it's greater than 30.
So let's say we've been sitting here for more than 30s if we have, that means we've been sitting here
for way too long and we're just going to kick ourselves.
So we'll reference the local player, we'll just kick ourselves and give a message like teleport timed
out.
And that kind of just fixes our problem there.
And I'm pretty sure that is all of the actions we need to listen to on the client.
So let's go ahead and verify that real quick.
So if we access our server action enums dot two client.
We have one two, three, four, five, six, seven and we have one two, 34567.
Cool.
We have listened to all of the actions.
The next thing we need to do is we need to set up the functions for all of the different buttons and
our GUI.
And of course, this lecture is already getting a little bit long, so we're going to go ahead and wrap
that up in the next lecture.
See you there.